import { useContext, useEffect } from "react"
import { RouteContext, SetRouteContext } from "../context/RouteContext"
import { Router } from "../routes"

function useRouter() {
    const route = useContext(RouteContext)
    const setRoute = useContext(SetRouteContext)
    Router.setUpdateFn(setRoute)
    if (!setRoute) {
        throw new Error('useRouter must be used within a RouterProvider')
    }
    // useEffect(() => {
    //     Router.pushRoute(route)
    //     return () => {
    //         Router.popRoute()
    //     }
    // }, [route])
    return route
}

export default useRouter